home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / util / wb / AmiStart.lha / ToolsSDK.lha / source / ModuleFuncs.c < prev    next >
C/C++ Source or Header  |  2002-06-15  |  19KB  |  751 lines

  1. /*
  2. **      $VER: ModuleFuncs.c 39.0 (15.03.02)
  3. **
  4. **      Functions for showram.tool
  5. **
  6. **        by Darius Brewka, based on Sample Library code "CLib37x" by
  7. **          (C) Copyright 1996-97 Andreas R. Kleinert
  8. **          All Rights Reserved.
  9. */
  10.  
  11. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15.  
  16. #ifdef __MAXON__
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/dos_protos.h>
  20. #include <clib/mui_protos.h>
  21. #else
  22. #include <proto/exec.h>
  23. #include <proto/intuition.h>
  24. #include <proto/dos.h>
  25. #include <proto/muimaster.h>
  26. #include <intuition/intuition.h>
  27. #endif
  28.  
  29. #include <graphics/layers.h>
  30. #include <libraries/mui.h>
  31.  
  32. #include "string.h"
  33.  
  34. #include "compiler.h"
  35.  
  36. #define PREFS_VERSION 1234
  37.  
  38. /* Buffer types */
  39.  
  40. #define         TOOLS_TYPE_BITMAP          1
  41. #define      TOOLS_TYPE_TRUECOLOR      2
  42.  
  43. /* Message Flags */
  44.  
  45. #define    TOOLS_FLAG_FMOUSE    1
  46. #define    TOOLS_FLAG_FKEY        2
  47. #define    TOOLS_FLAG_FTIMER    4
  48. #define    TOOLS_FLAG_NOSETUP    8
  49.  
  50. #define        STACKSIZE                2048
  51. #define        TASK_PRI                0
  52.  
  53. #define PaintTool(hd, hook) CallHook(hook, (Object *) hd, NULL)
  54.  
  55. /* global stuff */
  56.  
  57. #define    ASCLASS_MOUSE        1
  58. #define    ASCLASS_TIMER        2
  59. #define    ASCLASS_START        3
  60. #define    ASCLASS_STOP        4
  61.  
  62.     typedef struct asMessage {
  63.         struct    Message msg;
  64.                 UWORD    class;
  65.                 UWORD    code;
  66.                 UWORD    x;
  67.                 UWORD    y;
  68.     } asMSG;
  69.  
  70. /* some demo tool specific stuff, you can use it as a startup for your own tools */
  71.  
  72. #define    TIMERDEVICE
  73. #define    SECS    0
  74. #define    MICROS    250000
  75.  
  76. #ifdef TIMERDEVICE
  77.     struct    Device    *TimerBase = NULL;
  78. #endif
  79.  
  80. #define    MAXWIDTH    128
  81. #define    MINWIDTH    52
  82.  
  83. #define    MAXHEIGHT    64
  84. #define    MINHEIGHT    16
  85.  
  86.     struct    Library    *MUIMasterBase = NULL;
  87.             int        libcnt = 0;
  88.  
  89.     typedef struct toolsPrefs {
  90.                 UWORD    version;
  91.                 UWORD    width;
  92.                 UWORD    height;
  93.                 UBYTE    transp;
  94.                 UBYTE    textr, textg, textb;
  95.                 UBYTE    noborder;
  96.     } tP;
  97.  
  98.     typedef struct newT {
  99.                 APTR        pool;
  100.                 APTR        hd;
  101.                 ULONG        *bm;
  102.                 ULONG        *buffer;
  103.                 UWORD        w;
  104.                 UWORD        h;
  105.                 BOOL        run;
  106.         struct    Hook         *paint;
  107.         struct    toolsPrefs    prefs;
  108.                 UBYTE        p[MAXWIDTH];
  109.  
  110.         /* following is for the time device initialisation */
  111.  
  112. #ifdef    TIMERDEVICE
  113.         struct    MsgPort         *TimePort;
  114.         struct    timerequest     *TimeReq;
  115. #endif
  116.  
  117.         /* following is for creating the message port an the task */
  118.  
  119.  
  120.         struct    Task     task;
  121.         struct    Task    *maintask;
  122.         struct    MsgPort    *mp;
  123.                 ULONG    sigstart;
  124.                 ULONG    sigstop;
  125.                 ULONG    sigmask;
  126.                 ULONG    sigmsg;
  127.                 UBYTE    stack[STACKSIZE];
  128.     } Tool;
  129.  
  130.     char    ToolDescription[] = "Displays the amount of free Memory.";
  131.  
  132. /* to copy TrueColor data from a source to a destination */
  133.  
  134. void copyMap(ULONG *s, ULONG *d, UWORD w, UWORD h) {
  135.    CopyMem(s, d, w*h*sizeof(ULONG));
  136. }
  137.  
  138. #define numCols    64
  139.  
  140. /* a simple gradient for the "level-meter" */
  141.  
  142.     ULONG    colors[] = {
  143.         0xffAC4A48,    0xffB9605E,    0xffBC685F,    0xffC07061,    0xffC37862,    0xffC78064,    0xffCA8865,    0xffCC9167,
  144.         0xffCD9B68,    0xffCFA46A,    0xffD1AD6C,    0xffD2B76D,    0xffD4C06F,    0xffD8C76F,    0xffDDCE70,    0xffE1D570,
  145.         0xffE5DC70,    0xffEAE371,    0xffEEEA71,    0xffE8E970,    0xffE2E96F,    0xffDCE86E,    0xffD6E76D,    0xffD0E76C,
  146.         0xffCAE66B,    0xffC5E56A,    0xffC0E469,    0xffBBE368,    0xffB5E366,    0xffB0E265,    0xffABE164,    0xffA6E063,
  147.         0xff9BDD62,    0xff90DA60,    0xff85D65F,    0xff7AD35E,    0xff6FD05C,    0xff64CD5B,    0xff68CC66,    0xff6CCB70,
  148.         0xff70CB7B,    0xff73CA85,    0xff77C990,    0xff7BC89A,    0xff7FCAA6,    0xff82CCB2,    0xff86CFBD,    0xff89D1C9,
  149.         0xff8AD0CC,    0xff8CCFCE,    0xff8DCFD1,    0xff8ECED4,    0xff90CDD6,    0xff91CCD9,    0xff8EC4D1,    0xff8ABDC9,
  150.         0xff87B5C1,    0xff83AEB9,    0xff80A6B1,    0xff7C9FA9,    0xff7997A1,    0xff759099,    0xff728891,    0xff6E8189
  151.     };
  152.  
  153.  
  154.     char    *ramPic[] = {
  155.         "    000000000000000000 00000 0000000000000",
  156.         " 000000000000000000000  000  0000000000000",
  157.         " 000000000000000000000 0 0 0 0000000000000",
  158.         "   00 0 00   000   000 00 00 00   00 0 0 0",
  159.         " 0000  00 000 0 000 00 00000 0 000 0  0 0 ",
  160.         " 0000 000    00    000 00000 0    00 0000 ",
  161.         " 0000 000 00000 000000 00000 0 00000 0000 ",
  162.         " 0000 0000   000   000 00000 00   00 0000 ",
  163.     };
  164.  
  165. void paintText(Tool *t, char **pic, int x, int y, int w, int h) {
  166.     char    *p;
  167.     ULONG    *rgb, col;
  168.     int        x0, y0, yp;
  169.  
  170.     if (t->buffer == NULL) return;
  171.  
  172.     col = 0xff000000 | t->prefs.textr << 16 | t->prefs.textg << 8 | t->prefs.textb;
  173.     rgb = t->buffer;
  174.     yp = y * t->w;
  175.     for (y0 = 0; y0 < h; y0++) {
  176.         p = *pic++;
  177.         if (p) {
  178.             for (x0 = 0; x0 < w; x0++) {
  179.                 if (p[x0] == ' ') rgb[x0+x+yp] = col;
  180.             }
  181.         }
  182.         yp += t->w;
  183.     }
  184. }
  185.  
  186. /* create the free-ram "level-meter" */
  187.  
  188. void makeBar(Tool *t) {
  189.     UWORD    x, y, y1, ah, w, h;
  190.     ULONG    *rgb;
  191.     ULONG    free, total, p, td, q, pen, col;
  192.     UWORD    r, g, b;
  193.     UWORD    r0, g0, b0;
  194.  
  195.     free = AvailMem(MEMF_ANY);
  196.     total = AvailMem(MEMF_TOTAL);
  197.  
  198.     free = UDivMod32(free, MAXWIDTH);
  199.     total = UDivMod32(total, MAXWIDTH);
  200.  
  201.     y1 = t->h - 3;
  202.  
  203.     rgb = t->buffer;
  204.  
  205.     p = UDivMod32(free * (t->w -6), total);
  206.  
  207.     q = 0;
  208.  
  209.     if (p > (t->w - 3)) p = t->w - 3;
  210.  
  211.     w = 42;
  212.     h = 8;
  213.  
  214.     x = t->w - w;
  215.     y = t->h - h;
  216.  
  217.     paintText(t, ramPic, x >> 1, y >> 1, w, h);
  218.  
  219.  
  220.     for (x = 3; x < (3 + p); x++) {
  221.         ah = 3 * t->w;
  222.         pen = t->p[q];
  223.         if (pen != 0xff) {
  224.             if (pen < 129) col = colors[pen]; else col = 0;
  225.             r0 = (col >> 16) & 0xff;
  226.             g0 = (col >> 8) & 0xff;
  227.             b0 = col & 0xff;
  228.  
  229.             r0 *= 3;
  230.             g0 *= 3;
  231.             b0 *= 3;
  232.  
  233.             for (y = 3; y < y1; y++) {
  234.  
  235.  
  236.                 r = (r0 + ((rgb[x+ah] >> 16) & 0xff)) >> 2;
  237.                 g = (g0 + ((rgb[x+ah] >> 8) & 0xff)) >> 2;
  238.                 b = (b0 + (rgb[x+ah] & 0xff)) >> 2;
  239.  
  240.  
  241.  
  242.                 rgb[x+ah] = 0xff000000 | r << 16 | g << 8 |b;
  243.                 ah += t->w;
  244.             }
  245.         }
  246.         q++;
  247.     }
  248.  
  249.  
  250. }
  251.  
  252. /* the MessageHandler is the Main Task which recieves Messages form AmiStart and has to handle them */
  253.  
  254. void SAVEDS ASM __interrupt MessageHandler() {
  255.     struct    newT    *nt;
  256.     struct    Task    *task;
  257.             BOOL    ok;
  258.  
  259.             asMSG    *msg;
  260.  
  261.             ULONG    mask;
  262.             BOOL    running;
  263.  
  264.     task = FindTask(NULL);
  265.  
  266.     nt = (struct newT *) task->tc_UserData;
  267.  
  268.     nt->mp = CreateMsgPort();
  269.  
  270.     nt->sigstop = AllocSignal(-1);              // only one signal of 16 -> no test
  271.  
  272. #ifdef TIMERDEVICE
  273.     ok = FALSE;
  274.  
  275.     nt->TimePort = CreateMsgPort();
  276.     if (nt->TimePort) {
  277.            nt->TimeReq = (struct timerequest *) CreateIORequest(nt->TimePort,sizeof(struct timerequest));
  278.           if(nt->TimeReq != NULL) {
  279.             if(OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *) nt->TimeReq,0) == 0) {
  280.                 if (TimerBase == NULL) TimerBase = nt->TimeReq->tr_node.io_Device;
  281.                 ok = TRUE;
  282.             }
  283.         }
  284.     }
  285. #endif
  286.  
  287.     Signal(nt->maintask, 1 << nt->sigstart);
  288.  
  289.     if (nt->mp) {
  290.         nt->sigmsg = nt->mp->mp_SigBit;
  291.         nt->sigmask = (1 << nt->sigstop) | (1 << nt->sigmsg) ;
  292.  
  293. #ifdef TIMERDEVICE
  294.         if (ok) {
  295.             nt->sigmask |= (1 << nt->TimePort->mp_SigBit);
  296.             nt->TimeReq->tr_node.io_Command = TR_ADDREQUEST;
  297.             nt->TimeReq->tr_time.tv_secs    = 0;
  298.             nt->TimeReq->tr_time.tv_micro   = 500000;
  299.             SendIO((struct IORequest *) nt->TimeReq);
  300.         }
  301.  
  302. #endif
  303.  
  304.         /************************************************
  305.          * MAIN Loop                                    *
  306.          ************************************************/
  307.  
  308.         running = TRUE;
  309.  
  310.         nt->run = FALSE;
  311.  
  312.         while (running) {
  313.             mask = Wait(nt->sigmask);
  314.  
  315.             if ((mask & (1 << nt->sigstop))) running = FALSE;
  316.             if ((mask & (1 << nt->sigmsg)) && running) {
  317.  
  318.                 /*****************************************************
  319.                  * you don't need to do a loop, coz only one message *
  320.                  * will be send                                      *
  321.                  *****************************************************/
  322.  
  323.                 msg = (asMSG *) GetMsg(nt->mp);
  324.                 if (msg) {
  325.                     if (msg->class == ASCLASS_STOP) {
  326.                         nt->run = FALSE;
  327.                     } else if (msg->class == ASCLASS_START) {
  328.                         nt->run = TRUE;
  329.                         copyMap(nt->bm, nt->buffer, nt->w, nt->h);
  330.                         makeBar(nt);
  331.                         PaintTool(nt->hd, nt->paint);
  332.                     } else if (msg->class == ASCLASS_MOUSE && nt->run) {
  333.                     } else if (msg->class == ASCLASS_TIMER && nt->run) {
  334.                     }
  335.                 }
  336.                 if (msg) ReplyMsg((struct Message *) msg);
  337.             }
  338. #ifdef TIMERDEVICE
  339.             if (ok && running) {
  340.                 if (mask & (1 << nt->TimePort->mp_SigBit)) {
  341.                     WaitIO((struct IORequest *) nt->TimeReq);
  342.  
  343.                     if (nt->run) {
  344.                         copyMap(nt->bm, nt->buffer, nt->w, nt->h);
  345.                         makeBar(nt);
  346.                         PaintTool(nt->hd, nt->paint);
  347.                     }
  348.  
  349.                     nt->TimeReq->tr_node.io_Command = TR_ADDREQUEST;
  350.                     nt->TimeReq->tr_time.tv_secs = SECS;
  351.                     nt->TimeReq->tr_time.tv_micro   = MICROS;
  352.                     SendIO((struct IORequest *) nt->TimeReq);
  353.                 }
  354.             }
  355. #endif
  356.         }
  357.     } else {
  358.         Wait(1 << nt->sigstop);
  359.     }
  360.  
  361.     FreeSignal(nt->sigstop);
  362.  
  363. #ifdef TIMERDEVICE
  364.     if (ok) {
  365.         AbortIO((struct IORequest *) nt->TimeReq);
  366.         WaitIO((struct IORequest *) nt->TimeReq);
  367.         CloseDevice((struct IORequest *) nt->TimeReq);
  368.     }
  369.  
  370.     if (nt->TimeReq) DeleteIORequest((struct IORequest *) nt->TimeReq);
  371.     if (nt->TimePort) DeletePort(nt->TimePort);
  372. #endif
  373.  
  374.     if (nt->sigstart != -1) Signal(nt->maintask, 1 << nt->sigstart);
  375.  
  376.     if (nt->mp) DeleteMsgPort(nt->mp);
  377.  
  378.     Wait(0);
  379.  
  380. }
  381.  
  382. BOOL SAVEDS ASM OpenTool() {
  383.     BOOL    back = FALSE;
  384.     if (MUIMasterBase == NULL) {
  385.         MUIMasterBase = OpenLibrary("muimaster.library", 19);
  386.     }
  387.  
  388.     if (MUIMasterBase) {
  389.         libcnt++;
  390.         back = TRUE;
  391.     }
  392.  
  393.     return back;
  394. }
  395.  
  396. void SAVEDS ASM CloseTool() {
  397.     if (MUIMasterBase) {
  398.         libcnt--;
  399.         if (libcnt <= 0) {
  400.             CloseLibrary(MUIMasterBase);
  401.             MUIMasterBase = NULL;
  402.         }
  403.     }
  404. }
  405.  
  406.  
  407. STRPTR SAVEDS ASM ToolInfo() {
  408.     return ToolDescription;
  409. }
  410.  
  411. APTR SAVEDS ASM NewTool(REG(a0) tP *prefs, REG(a1) APTR pool) {
  412.     struct    newT    *nt;
  413.             BOOL    usedefault;
  414.             UBYTE    *s, *d;
  415.             int        p;
  416.  
  417.     nt = AllocPooled(pool, sizeof(struct newT));
  418.     if (nt) {
  419.  
  420.         usedefault = TRUE;
  421.         if (prefs) {
  422.             /* prefs are passed by AmiStart */
  423.             if (prefs->version == PREFS_VERSION) {
  424.                 s = (UBYTE*) prefs;
  425.                 d = (UBYTE*) &nt->prefs;
  426.                 for (p = 0; p < sizeof(tP); p++) *d++ = *s++;
  427.                 nt->prefs.width = prefs->width;
  428.                 nt->prefs.height = prefs->height;
  429.                 usedefault = FALSE;
  430.             }
  431.         }
  432.  
  433.         if (usedefault) {
  434.             /* if no prefs are passed use default prefs */
  435.             nt->prefs.width = MINWIDTH;
  436.             nt->prefs.height = MINHEIGHT;
  437.         }
  438.  
  439.  
  440.         if (nt->prefs.width < MINWIDTH) nt->prefs.width = MINWIDTH;
  441.         if (nt->prefs.width > MAXWIDTH) nt->prefs.width = MAXWIDTH;
  442.         if (nt->prefs.height < MINHEIGHT) nt->prefs.height = MINHEIGHT;
  443.         if (nt->prefs.height > MAXHEIGHT) nt->prefs.height = MAXHEIGHT;
  444.  
  445.         nt->sigstart = AllocSignal(-1);
  446.         if (nt->sigstart != -1) {
  447.             nt->pool = pool;
  448.             nt->task.tc_Node.ln_Pri = TASK_PRI;
  449.             nt->task.tc_Node.ln_Type = NT_TASK;
  450.             nt->task.tc_SPLower = (APTR) nt->stack;
  451.             nt->task.tc_SPUpper = (APTR) ((ULONG) nt->stack+STACKSIZE);
  452.             nt->task.tc_SPReg = (APTR) ((ULONG) nt->stack+STACKSIZE);
  453.             nt->task.tc_UserData = nt;
  454.             nt->maintask = FindTask(NULL);
  455.             AddTask(&nt->task, (APTR) MessageHandler, NULL);        /* create the Tool Task */
  456.             Wait(1 << nt->sigstart);
  457.             if (nt->mp == NULL) {
  458.                 Signal(&nt->task, 1 << nt->sigstop);
  459.                 if (nt->sigstart != -1) Wait (1 << nt->sigstart);
  460.                 RemTask(&nt->task);
  461.             }
  462.               FreeSignal(nt->sigstart);
  463.         } else {
  464.             FreePooled(pool, nt, sizeof(struct newT));
  465.             nt = NULL;
  466.         }
  467.     }
  468.     return nt;
  469. }
  470.  
  471. UWORD SAVEDS ASM ToolWidth(REG(a0) Tool *tool, REG(d0) UWORD width) {
  472.     tool->w = tool->prefs.width;
  473.     return tool->prefs.width;
  474. }
  475.  
  476. UWORD SAVEDS ASM ToolHeight(REG(a0) Tool *tool, REG(d0) UWORD height) {
  477.     tool->h = tool->prefs.height;
  478.     return tool->prefs.height;
  479. }
  480.  
  481. void SAVEDS ASM InitTool(REG(a0) Tool *tool, REG(a1) APTR bm, REG(a2) APTR buffer, REG(a3) struct Hook *hook, REG(a4) APTR t) {
  482.  
  483.     ULONG    *raw, rgb, td, q, pen;
  484.     int        x,y,h,w;
  485.     BOOL    f0,f1;
  486.  
  487.     tool->bm = (ULONG *) bm;
  488.     tool->buffer = (ULONG *) buffer;
  489.     tool->hd = t;
  490.     tool->paint = hook;
  491.  
  492.        w = tool->w;
  493.      h = tool->h;
  494.  
  495.     /* make some visula initializations, and initialize the level-meter buffers */
  496.  
  497.     if (tool->bm && tool->buffer) {
  498.         raw = (ULONG* ) buffer;
  499.         if (!tool->prefs.noborder) {
  500.             for (x=0; x < w; x++) {
  501.                 raw[x] = 0xff888888;
  502.                 raw[x+(h-1)*w] = 0xff888888;
  503.             }
  504.             for (x=1; x < (w-1); x++) {
  505.                 raw[x+w] = 0xff444444;
  506.                 raw[x+(h-2)*w] = 0xff444444;
  507.             }
  508.             for (y=0; y < h; y++) {
  509.                 raw[y*w] = 0xff888888;
  510.                 raw[y*w+w-1] = 0xff888888;
  511.             }
  512.             for (y=1; y < (h-1); y++) {
  513.                 raw[y*w+1] = 0xff444444;
  514.                 raw[y*w+w-2] = 0xff444444;
  515.             }
  516.         }
  517.  
  518.         if (!tool->prefs.transp) {
  519.             f1 = FALSE;
  520.  
  521.             for (y = 2; y < (h-2) ; y++) {
  522.                 f0 = f1;
  523.                 for (x = 2; x < (w-2); x++) {
  524.                     if (f1) {
  525.                         if (f0) rgb = 0xffcccccc; else rgb = 0xffaaaaaa;
  526.                     } else {
  527.                         if (f0) rgb = 0xffbbbbbb; else rgb = 0xff999999;
  528.                     }
  529.                     raw[x+y*w] = rgb;
  530.                     f0 = !f0;
  531.                 }
  532.                 f1 = !f1;
  533.             }
  534.         }
  535.  
  536.         copyMap(tool->buffer, tool->bm, tool->w, tool->h);
  537.  
  538.         w -= 6;
  539.  
  540.         td = w;
  541.  
  542.         for (q = 0; q < w; q++) {
  543.             pen = UDivMod32(q*numCols, td);
  544.             if (pen >= numCols) pen = numCols - 1;
  545.             tool->p[q] = (UBYTE) pen;
  546.         }
  547. /*
  548.         w = UDivMod32(w, 3);
  549.  
  550.         for (q = 0; q < w; q++) {
  551.             pen = UDivMod32(q*3*numCols, td);
  552.             if (pen >= numCols) pen = numCols - 1;
  553.             tool->p[q*3+0] = (UBYTE) pen;
  554.             tool->p[q*3+1] = (UBYTE) pen;
  555.             tool->p[q*3+2] = (UBYTE) pen;    //0xfe;    //pen;
  556.         }
  557. */
  558.  
  559.     }
  560. }
  561.  
  562. void SAVEDS ASM DisposeTool(REG(a0) Tool *tool) {
  563.     if (tool) {
  564.         tool->sigstart = AllocSignal(-1);
  565.         Signal(&tool->task, 1 << tool->sigstop);
  566.         if (tool->sigstart != -1) Wait (1 << tool->sigstart);
  567.         RemTask(&tool->task);                                     /* stop the Tool Task */
  568.         if (tool->sigstart != -1) FreeSignal(tool->sigstart);
  569.         FreePooled(tool->pool, (UBYTE*) tool, sizeof(struct newT));
  570.     }
  571. }
  572.  
  573. ULONG SAVEDS ASM GetToolFlags(REG(a0) Tool *tool) {
  574.     // return TOOLS_FLAG_FMOUSE|TOOLS_FLAG_NOSETUP;
  575.     return 0;
  576. }
  577.  
  578. struct MsgPort SAVEDS ASM *GetToolPort(REG(a0) Tool *tool) {
  579.     return tool->mp;
  580. }
  581.  
  582. UWORD DisplayToolSetup(Tool *);
  583.  
  584. UWORD SAVEDS ASM ToolSetup(REG(a0) Tool *tool, REG(d0) UWORD MouseX, REG(d1) UWORD MouseY) {
  585.     return DisplayToolSetup(tool);
  586. }
  587.  
  588. APTR SAVEDS ASM GetToolPrefs(REG(a0) Tool *tool) {
  589.     tool->prefs.version = PREFS_VERSION;
  590. //    tool->prefs.width = tool->w;
  591. //    tool->prefs.height = tool->h;
  592.     return (APTR) &tool->prefs;
  593. }
  594.  
  595. int SAVEDS ASM GetToolPrefsSize(REG(a0) Tool *tool) {
  596.     return sizeof(struct toolsPrefs);
  597. }
  598.  
  599. UWORD SAVEDS ASM GetToolBufferType(REG(a0) Tool *tool) {
  600.     return TOOLS_TYPE_TRUECOLOR;
  601. }
  602.  
  603.  
  604. #define    SP_TRANSPARENT    1
  605. #define    SP_TEXTCOLOR    2
  606. #define SP_NOBORDER        3
  607.  
  608. Object    *PenObject(UBYTE r, UBYTE g, UBYTE b) {
  609.  
  610.     return ColorfieldObject,
  611.         ImageButtonFrame,
  612.         MUIA_CycleChain,  1,
  613.         MUIA_InputMode        , MUIV_InputMode_RelVerify,
  614.         MUIA_Colorfield_Red, r << 24,
  615.         MUIA_Colorfield_Green, g << 24,
  616.         MUIA_Colorfield_Blue, b << 24,
  617.     End;
  618. }
  619.  
  620.  
  621. UWORD DisplayToolSetup(Tool *tool) {
  622.     Object  *app, *win;
  623.  
  624.     Object    *transpObject, *noborderObject, *wObject, *hObject, *textcolorObject;
  625.     Object    *textcolorwin, *textpenObject, *textcolorokObject, *textcolorcancelObject;
  626.  
  627.     BOOL    running = TRUE;
  628.     ULONG   signals;
  629.     ULONG   rtsm, id, nr;
  630.     UWORD    back;
  631.  
  632.     back = 0;
  633.  
  634.     if (MUIMasterBase == NULL) return 0;
  635.     app = ApplicationObject,
  636.         MUIA_Application_Title,     "Tools Setup",
  637.         MUIA_Application_Base,      "AMISTART",
  638.  
  639.         SubWindow, win = WindowObject,
  640.               MUIA_Window_Activate,         TRUE,
  641.               MUIA_Window_DepthGadget,     TRUE,
  642.             MUIA_Window_DragBar,         TRUE,
  643.             MUIA_Window_SizeGadget,     TRUE,
  644.             MUIA_Window_AppWindow,      TRUE,
  645.             MUIA_Window_CloseGadget,    TRUE,
  646.             MUIA_Window_Borderless,     FALSE,
  647.             MUIA_Window_Title,             "Show Ram ToolSetup",
  648.             MUIA_Window_TopEdge,        MUIV_Window_TopEdge_Moused,
  649.             MUIA_Window_LeftEdge,       MUIV_Window_LeftEdge_Moused,
  650.  
  651.             WindowContents, VGroup,
  652.                 Child, HGroup,
  653.                     Child, Label2("Transparent"),
  654.                     Child, HVSpace,
  655.                     Child, transpObject = CheckMark(tool->prefs.transp),
  656.                 End,
  657.                 Child, HGroup,
  658.                     Child, Label2("No Border"),
  659.                     Child, HVSpace,
  660.                     Child, noborderObject = CheckMark(tool->prefs.noborder),
  661.                 End,
  662.                 Child, ColGroup(2),
  663.                     Child, Label2("Width:"),
  664.                     Child, wObject = Slider(MINWIDTH, MAXWIDTH, tool->prefs.width),
  665.                     Child, Label2("Height:"),
  666.                     Child, hObject = Slider(MINHEIGHT, MAXHEIGHT, tool->prefs.height),
  667.                     Child, Label2("Text Color:"),
  668.                     Child, textcolorObject = PenObject(tool->prefs.textr, tool->prefs.textg, tool->prefs.textb),
  669.                 End,
  670.             End,
  671.         End,
  672.  
  673.  
  674.         SubWindow, textcolorwin = WindowObject,
  675.             MUIA_Window_Open, FALSE,
  676.             MUIA_Window_CloseGadget, FALSE,
  677.             WindowContents, VGroup,
  678.                 Child, textpenObject = ColoradjustObject,
  679.                     MUIA_Coloradjust_Red,      tool->prefs.textr << 24,
  680.                     MUIA_Coloradjust_Green,    tool->prefs.textg << 24,
  681.                     MUIA_Coloradjust_Blue,     tool->prefs.textb << 24,
  682.                 End,
  683.                 Child, ColGroup(2),
  684.                     Child, textcolorokObject = KeyButton("OK",0),
  685.                     Child, textcolorcancelObject = KeyButton("Cancel",0),
  686.                 End,
  687.             End,
  688.         End,
  689.  
  690.  
  691.  
  692.     End;
  693.  
  694.     if (app) {
  695.         DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  696.         DoMethod(transpObject,MUIM_Notify,MUIA_Selected,MUIV_TriggerValue,app,2,MUIM_Application_ReturnID,SP_TRANSPARENT);
  697.         DoMethod(noborderObject,MUIM_Notify,MUIA_Selected,MUIV_TriggerValue,app,2,MUIM_Application_ReturnID,SP_NOBORDER);
  698.         DoMethod(textcolorObject, MUIM_Notify, MUIA_Pressed, TRUE, textcolorwin, 4, MUIM_Set, MUIA_Window_Open, TRUE);
  699.         DoMethod(textcolorcancelObject,MUIM_Notify,MUIA_Selected, MUIV_TriggerValue, textcolorwin, 4, MUIM_Set, MUIA_Window_Open, FALSE);
  700.         DoMethod(textcolorokObject,MUIM_Notify,MUIA_Pressed, TRUE,app,2,MUIM_Application_ReturnID,SP_TEXTCOLOR);
  701.  
  702.         set(win,MUIA_Window_Open,TRUE);
  703.  
  704.         while (running) {
  705.             id = DoMethod(app,MUIM_Application_Input,&signals);
  706.  
  707.             switch (id) {
  708.  
  709.                 case MUIV_Application_ReturnID_Quit:
  710.                     get(wObject, MUIA_Slider_Level, &rtsm);
  711.                     tool->prefs.width = (UWORD) rtsm;
  712.                     get(hObject, MUIA_Slider_Level, &rtsm);
  713.                     tool->prefs.height = (UWORD) rtsm;
  714.                     running = FALSE;
  715.                     break;
  716.  
  717.                 case SP_TRANSPARENT:
  718.                     get(transpObject,MUIA_Selected,&rtsm);
  719.                     if (rtsm) tool->prefs.transp = TRUE; else tool->prefs.transp = FALSE;
  720.                     break;
  721.  
  722.                 case SP_NOBORDER:
  723.                     get(noborderObject,MUIA_Selected,&rtsm);
  724.                     if (rtsm) tool->prefs.noborder = TRUE; else tool->prefs.noborder = FALSE;
  725.                     break;
  726.  
  727.                 case SP_TEXTCOLOR:
  728.                     set(textcolorwin, MUIA_Window_Open, FALSE);
  729.  
  730.                     get(textpenObject,MUIA_Coloradjust_Red, &rtsm);
  731.                     set(textcolorObject, MUIA_Colorfield_Red, rtsm);
  732.                     tool->prefs.textr = (UBYTE) ((rtsm >> 24) & 0xff);
  733.                     get(textpenObject,MUIA_Coloradjust_Green, &rtsm);
  734.                     set(textcolorObject, MUIA_Colorfield_Green, rtsm);
  735.                     tool->prefs.textg = (UBYTE) ((rtsm >> 24) & 0xff);
  736.                     get(textpenObject,MUIA_Coloradjust_Blue, &rtsm);
  737.                     set(textcolorObject, MUIA_Colorfield_Blue, rtsm);
  738.                     tool->prefs.textb = (UBYTE) ((rtsm >> 24) & 0xff);
  739.  
  740.                     break;
  741.  
  742.  
  743.             } if (running && signals) Wait(signals);
  744.         }
  745.         set(win,MUIA_Window_Open,FALSE);
  746.         MUI_DisposeObject(app);
  747.     }
  748.  
  749.     return back;
  750. }
  751.